package com.guoqing.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.guoqing.entity.Cook;
import com.guoqing.jdbcUtil.Util;
 public class CookDaoImpl implements CookDao {
	private PreparedStatement ps;
	private Connection conn;
	private ResultSet rs;
	@Override
	public void addCook(Cook cook) {
		System.out.println(cook.getPaypeople());
		conn= Util.getConnection();
		String sql = "insert into cook(datetime,people,paypeople,toto,avg) values(?,?,?,?,?)";
		try {
			ps = conn.prepareStatement(sql);
			ps.setDate(1, cook.getDate());
			ps.setString(2, cook.getPeople());
			ps.setString(3, cook.getPaypeople());
			ps.setDouble(4, cook.getToto());
			ps.setDouble(5, cook.getAvg());
			ps.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally
		{
			if(null != conn)
			{
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
				
			}
			if(null != ps)
			{
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}

		
	}

}
